package com.night.icm.service.core.mapper;

import com.night.icm.model.core.UserDTO;
import com.night.icm.persistence.core.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;

/**
 * UserMapper
 *
 * @author Liao ZhiYong
 * @date 2019/12/10
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserMapper {

    /**
     * 实体转成DTO
     *
     * @param userEntity 实体
     * @return 返回值
     */
    UserDTO toDTO(User userEntity);

    /**
     * DTO转为实体
     *
     * @param userDTO DTO
     * @return 返回值
     */
    User toEntity(UserDTO userDTO);

    /**
     * 实体集合转为DTO集合
     *
     * @param content 实体集合
     * @return DTO集合
     */
    List<UserDTO> toList(List<User> content);

    /**
     * 更新一个已经存在的实体数据
     *
     * @param userDTO 存在的dto
     * @param user 更新后的实体用户
     */
    void updateEntity(UserDTO userDTO, @MappingTarget User user);
}
